#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=1000;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

int get(int l, int r, int x, int y) {
  if (x==l && y==r) {
    return 1;
  } else {
    int mid=(l+r)/2, ret=1;
    if (x<=mid && y>=l) {
      ret = ret+get(l, mid, max(l, x), min(mid, y));
    }
    if (x<=r && y>mid) {
      ret = ret+get(mid+1, r, max(mid+1, x), min(r, y));
    }
    return ret;
  }
}

int main() {
  freopen("ran.in", "r", stdin);
  freopen("ran.out", "w", stdout);

  static int ans[maxn+1][maxn+1];
  int n, q, opt;
  scanf("%d %d %d", &n, &q, &opt);
  for (int i=1; i<=n; i++) {
    for (int j=i; j<=n; j++) {
      ans[i][j] = get(1, n, i, j);
    }
  }
  long long lastans=0;
  for (int i=1; i<=q; i++) {
    int l, r, a, b;
    scanf("%d %d", &l, &r);
    a = (l^(lastans*opt))%n+1, b = (r^(lastans*opt))%n+1;
    l = min(a, b), r = max(a, b);
    lastans = 0;
    for (int j=l; j<=r; j++) {
      for (int k=j; k<=r; k++) {
	lastans += ans[j][k];
      }
    }
    printf("%lld\n", lastans);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
